package com.hongshu.web.service.recommendation.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 推荐上下文模型
 *
 * @author hongshu
 * @date 2024/01/01
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RecommendContext {

    private long currentPage;
    private long pageSize;
    private long timestamp;
    private int currentHour;
    private int currentDayOfWeek;
    private String deviceType;
    private String networkType;
    private String location;

    /**
     * 获取当前小时
     */
    public int getCurrentHour() {
        if (currentHour == 0) {
            // 从timestamp计算当前小时
            java.util.Calendar calendar = java.util.Calendar.getInstance();
            calendar.setTimeInMillis(timestamp);
            return calendar.get(java.util.Calendar.HOUR_OF_DAY);
        }
        return currentHour;
    }

    /**
     * 获取当前星期几
     */
    public int getCurrentDayOfWeek() {
        if (currentDayOfWeek == 0) {
            // 从timestamp计算当前星期几
            java.util.Calendar calendar = java.util.Calendar.getInstance();
            calendar.setTimeInMillis(timestamp);
            return calendar.get(java.util.Calendar.DAY_OF_WEEK);
        }
        return currentDayOfWeek;
    }
}

